package com.vecspace.statistics.counter;

import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;

/**对一个时间段内的数量进行计数
 * @author: wanghua
 */
public class TimeCounter {	
	private int year, month, day, hour, minute,  second;
	private AtomicLong counterNum;
	/**
	 * 
	 * @param year 2017
	 * @param month 0-11
	 * @param day 1-31
	 * @param hour
	 * @param minute
	 * @param second
	 */
	public TimeCounter(int year, int month, int day, int hour, int minute, int second) {
		this.year = year;
		this.month = month;
		this.day = day;
		this.hour = hour;
		this.minute = minute;
		this.second = second;
		counterNum = new AtomicLong(0);
	}
	
	public long increment() {
		return counterNum.incrementAndGet();
	}
	
	public long add(int delta) {
		return counterNum.addAndGet(delta);
	}
	
	public long getCount() {
		return counterNum.get();
	}
	
	public Date getTime() {
		Calendar time = Calendar.getInstance();
		time.set(year, month, day, hour, minute, second);
		return time.getTime();
	}
}
